﻿<div style="height:30px;line-height:30px;text-align:center;vertical-align:middle;">
    <button type="button" class="ui-state-default ui-priority-primary ui-corner-all" value="全选" id="selectAllBtn" >全选</button>
    <button type="button" class="ui-state-default ui-priority-primary ui-corner-all" value="全不选" id="unselectAllBtn" >全不选</button>
    <button type="button" class="ui-state-default ui-priority-primary ui-corner-all" value="反选" id="selectOppoBtn" >反选</button>
</div>
<div style="overflow:auto;height:290px;">
    <input type="hidden" id="typenodesJson" value="@ViewBag.Types"/>
    <ul id="typestree" class="ztree"></ul>
</div>
<div style="height:30px;line-height:30px;text-align:right;vertical-align:middle">
    <button type="button" class="ui-state-default ui-priority-primary ui-corner-all" value="取消" id="cancelBtn" >取消</button>
    <button type="button" class="ui-state-default ui-priority-primary ui-corner-all" value="确定" id="confirmBtn" >确定</button>
    <input type="hidden" id="selectedTypes" />
</div>

<script>
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: null
            }
        },
        view: {
            showLine: true, //是否显示节点间的连线
            showIcon: true
        },
        check: {
            autoCheckTrigger: true,
            chkboxType: { "Y": "ps", "N": "ps" },
            chkStyle: "checkbox",
            enable: true,
            //radioType: "level"//"all"
        }
    };
    var treeNodes = $.parseJSON($("#typenodesJson").val());
    var zTree1 = $.fn.zTree.init($("#typestree"), setting, treeNodes);

    $("#typenodesJson").remove();

    //默认选择所有类型
    var types = zTree1.getCheckedNodes();
    if (types.length == 0) {
        artDialogAlert("请先选择要查询的车辆");
    }
    var v = "";
    $.each(types, function (index) {
        if (types[index].pId=="-1") {
            v += (types[index].id + ";");
        }
    });
    v = v.substring(0, v.length - 1);
    $("#selectedTypes").val(v);



    $("#selectAllBtn").click(function () {
        zTree1.checkAllNodes(true);
    });

    $("#unselectAllBtn").click(function () {
        zTree1.checkAllNodes(false);
    });

    $("#selectOppoBtn").click(function () {
        var nodes = zTree1.getNodes()[0].children;
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].checked == true) {
                zTree1.checkNode(nodes[i], false, true);
            }
            else {
                zTree1.checkNode(nodes[i], true, true);
            }
        }
    });

    $("#confirmBtn").click(function () {
        var types = zTree1.getCheckedNodes();
        if (types.length == 0) {
            artDialogAlert("请至少选择一个报警类型");
            return false;
        }
        var v = "";
        $.each(types, function (index) {
            if (types[index].pId == "-1") {
                v += (types[index].id + ";");
            }
        });
        v = v.substring(0, v.length - 1);
        $("#selectedTypes").val(v);

        $("#warnTypeDiv").hide();
    });

    $("#cancelBtn").click(function () {
        $("#warnTypeDiv").hide();
    });
</script>